package physical

import "github.com/oklog/ulid/v2"

// Limit represents a limiting operation in the physical plan that applies
// offset and limit to the result set. The offset specifies how many rows to
// skip before starting to return results, while limit specifies the maximum
// number of rows to return.
type Limit struct {
	NodeID ulid.ULID

	// Skip specifies how many initial rows should be skipped.
	Skip uint32
	// Fetch specifies how many rows should be returned in total.
	Fetch uint32
}

// ID implements the [Node] interface.
// Returns the ULID that uniquely identifies the node in the plan.
func (l *Limit) ID() ulid.ULID { return l.NodeID }

// Clone returns a deep copy of the node with a new unique ID.
func (l *Limit) Clone() Node {
	return &Limit{
		NodeID: ulid.Make(),

		Skip:  l.Skip,
		Fetch: l.Fetch,
	}
}

// Type implements the [Node] interface.
// Returns the type of the node.
func (*Limit) Type() NodeType {
	return NodeTypeLimit
}
